package avicit.cbb.businessclass.fondsmanage.service.api;


import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsDb;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsDbV;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsServer;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsServerV;
import avicit.im.common.CommonTreeNode;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CbbFondsDbServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/cbb/businessclass/fondsmanage/rest/CbbFondsDbServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     *加载全宗组织部门树
     * @param id
     * @param deptId
     * @param orgId
     * @return
     */
    public List<CommonTreeNode> getChildsNode(String id, String deptId, String orgId) {
        String url = BASE_PATH + "/getChildsNode";
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("deptId",deptId);
        map.put("orgId",orgId);
        ResponseMsg<List<CommonTreeNode>> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<List<CommonTreeNode>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *查询全宗信息
     * @param page
     * @param parameter
     * @return
     */
    public Page<Map<String, Object>> loadCbbFondsDb(Paging<CbbFondsDbV> page, Map<String, Object> parameter) {
        String url = BASE_PATH + "/loadCbbFondsDb";
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("parameter",parameter);
        ResponseMsg<Page<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Page<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 删除全宗记录
     * @param ids
     */
    public void deleteCbbFondsDb(String ids) {
        String url = BASE_PATH + "/deleteCbbFondsDb";
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     * 根据全宗记录ID删除全文服务器记录
     * @param ids
     */
    public void deleteCbbFondsServerByDbId(String ids) {
        String url = BASE_PATH + "/deleteCbbFondsServerByDbId";
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     *查询全文服务器设置信息
     * @param page
     * @param parameter
     * @return
     */
    public Page<Map<String, Object>> loadCbbFondsServer(Paging<CbbFondsServerV> page, Map<String, Object> parameter) {
        String url = BASE_PATH + "/loadCbbFondsServer";
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("parameter",parameter);
        ResponseMsg<Page<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<Page<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 删除全文服务器设置信息
     * @param ids
     */
    public void deleteCbbFondsServer(String ids) {
        String url = BASE_PATH + "/deleteCbbFondsServer";
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     * 获取部门编号、名称信息
     * @param orgId
     * @return
     */
    public Map<String, Object> getSysOrgInfo(String orgId) {
        String url = BASE_PATH + "/getSysOrgInfo";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 根据ID获取全宗视图对象
     * @param id
     * @return
     */
    public List<Map<String, Object>> getCbbFondsDbV(String id) {
        String url = BASE_PATH + "/getCbbFondsDbV";
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 根据ID获取全文服务器信息设置视图对象
     * @param id
     * @return
     */
    public List<Map<String, Object>> getCbbFondsServerV(String id) {
        String url = BASE_PATH + "/getCbbFondsServerV";
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 新增全宗管理记录
     * @param cbbFondsDb
     */
    public void insertCbbFondsDb(CbbFondsDb cbbFondsDb) {
        String url = BASE_PATH + "/insertCbbFondsDb";
        Map<String,Object> map = new HashMap<>();
        map.put("cbbFondsDb",cbbFondsDb);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
    }


    /**
     * 更新全宗管理记录
     * @param cbbFondsDb
     */
    public void updateCbbFondsDb(CbbFondsDb cbbFondsDb) {
        String url = BASE_PATH + "/updateCbbFondsDb";
        Map<String,Object> map = new HashMap<>();
        map.put("cbbFondsDb",cbbFondsDb);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
    }


    /**
     * 添加唯一性校验
     * @param fullsvrType
     * @param svrAddress
     * @param svrPublishPath
     * @param ftpUser
     * @return
     */
    public boolean saveUniqueValidate(String fullsvrType, String svrAddress, String svrPublishPath, String ftpUser) {
        String url = BASE_PATH + "/saveUniqueValidate";
        Map<String,Object> map = new HashMap<>();
        map.put("fullsvrType",fullsvrType);
        map.put("svrAddress",svrAddress);
        map.put("svrPublishPath",svrPublishPath);
        map.put("ftpUser",ftpUser);
        ResponseMsg<Boolean> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *新增全宗管理记录
     * @param cbbFondsServer
     */
    public void insertCbbFondsServer(CbbFondsServer cbbFondsServer) {
        String url = BASE_PATH + "/insertCbbFondsServer";
        Map<String,Object> map = new HashMap<>();
        map.put("cbbFondsServer",cbbFondsServer);
        ResponseMsg<Boolean> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
    }


    /**
     * 更新全文服务器记录
     * @param cbbFondsServer
     */
    public void updateCbbFondsServer(CbbFondsServer cbbFondsServer) {
        String url = BASE_PATH + "/updateCbbFondsServer";
        Map<String,Object> map = new HashMap<>();
        map.put("cbbFondsServer",cbbFondsServer);
        ResponseMsg<Boolean> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
    }


    /**
     * 编辑唯一性校验
     * @param id
     * @param fullsvrType
     * @param svrAddress
     * @param svrPublishPath
     * @param ftpUser
     * @return
     */
    public boolean editUniqueValidate(String id, String fullsvrType, String svrAddress, String svrPublishPath, String ftpUser) {
        String url = BASE_PATH + "/editUniqueValidate";
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("fullsvrType",fullsvrType);
        map.put("svrAddress",svrAddress);
        map.put("svrPublishPath",svrPublishPath);
        map.put("ftpUser",ftpUser);
        ResponseMsg<Boolean> responseMsg = restClient.doPost(SERVICE_CODE, url,map,  new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
